#ifndef TIME_WHEEL_H
#define TIME_WHEEL_H

#include <chrono>
#include <string>
#include <memory>
#include <vector>
#include <list>

#include "timer.h"

class TimeWheel
{
public:
    TimeWheel(uint32_t scales,
              uint32_t scale_unit_ms,
              const std::string& name= "");
public:
    uint32_t getScalesUnitms() const{
        return m_scale_uint_ms;
    }
    uint32_t getScales() const{
        return m_scales;
    }
    uint32_t getCurrentIndex() const{
        return m_current_index;
    }

    void setLessLevelTw(TimeWheel* less_level_tw){
        m_less_level_tw = less_level_tw;
    }

    void setGreaterLevelTw(TimeWheel* greater_level_tw){
        m_greater_level_tw = greater_level_tw;
    }

    int64_t getCurrentTime() const;

    void addTime(TimerPtr pTimer);

    void increase();

    std::list<TimerPtr> getAndClearCurrentSlot();
private:
    std::string m_name;
    uint32_t m_current_index;

    uint32_t m_scales;
    uint32_t m_scale_uint_ms;

    std::vector<std::list<TimerPtr>> m_slots;

    TimeWheel* m_less_level_tw;
    TimeWheel* m_greater_level_tw;
};

using TimeWheelPtr = std::shared_ptr<TimeWheel>;

inline int64_t getNowTimeStamp(){
    using namespace std::chrono;
    auto now = system_clock::now().time_since_epoch();
    return duration_cast<microseconds>(now).count();
}

#endif // TIME_WHEEL_H
